<template>
  <div id="home">
    <!-- 轮播图 -->
    <mt-swipe :auto="4000" class='swipe'>
      <mt-swipe-item v-for='item in imgs' :key='item.id'>
        <img :src="item.url" alt="" />
      </mt-swipe-item>
    </mt-swipe>

    <!-- 九宫格 -->
    <div class="nine">
      <ul>
        <li v-for="(item, index) in grids" :key='index'>
          <router-link :to="item.router">
            <img :src="item.src" alt="">
          </router-link>
          <p>{{ item.title }}</p>
        </li>
      </ul>
    </div>

  </div>
</template>

<script>
  export default {
    name: 'Home',
    data() {
      return {
        imgs: [],
        grids: [{
            id: 1,
            src: require('../../assets/img/nine-new.png'),
            title: '新闻资讯',
            // 命名路由
            router:{name:'news'}
          },
          {
            id: 2,
            src: require('../../assets/img/nine-new.png'),
            title: '图文分享',
            // 在命名路由中传递参数
            router:{name:'photos', params: {categoryId: 0}}
          },
          {
            id: 3,
            src: require('../../assets/img/nine-new.png'),
            title: '商品展示',
            router:{name:'news'}
          },
          {
            id: 4,
            src: require('../../assets/img/nine-new.png'),
            title: '资讯',
            router:{name:'news'}
          },
          {
            id: 5,
            src: require('../../assets/img/nine-new.png'),
            title: '联系我们',
            router:{name:'news'}
          }
        ]
      }
    },
    methods: {
      getAdvImg() {
        this.$http.get('/adv_imgs').then(res => {
          console.log(res.data.imgs);
          this.imgs = res.data.imgs;
        }).catch(err => {
          console.log('get data fail', err)
        })
      }
    },
    created() {
      this.getAdvImg();
    }

  }
</script>

<style lang="less" scoped>
  .swipe {
    width: 100%;
    height: 15.625rem;
  }

  .swipe img {
    width: 100%;
    height: 15.625rem;
  }

  .nine {
    width: 100%;
    margin-top: 1.25rem;
  }

  .nine ul {
    display: flex;
    flex-wrap: wrap;
  }

  .nine ul li {
    width: 33%;
    height: 6.25rem;
    font-size: 0.875rem;
    text-align: center;
  }

  .nine ul li a {
    display: inline-block;
    width: 50px;
    height: 50px;
    margin: 0px auto;
  }

  .nine ul li img {
    width: 3.125rem;
  }
</style>
